<template>
	<view class="search">
		<!-- 背景 -->
		<view class="bg">

		</view>
		<!-- 背景 -->
		<!-- 结构 -->
		<view class="product">
			<view class="group_item" @click="isShowPwd = true">
				<view class="item_l">修改密码</view>
				<view class="item_r">></view>
			</view>

			<view class="group_item" @click="isShowDestroyAccount = true">
				<view class="item_l">注销账号</view>
				<view class="item_r">></view>
			</view>

		</view>
		<view style="padding: 24rpx;">
			<u-button type="primary" @click="useLogout">退出登录</u-button>
		</view>

		<!-- 结构 -->

		<!-- 注销账号模态框 -->
		<u-modal v-model="isShowDestroyAccount" @confirm="useDestroyAccount" show-cancel-button content="确定注销此账号？">
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userImg: '',
				desc: '',
				nickName: '',
				isShowPwd: false, //修改密码
				isShowDestroyAccount: false, // 显示注销账号模态框
				rules: {
					old: [{
						required: true,
						pattern: /^[A-Za-z]\w{5,15}$/,
						message: '首字符必须为字母',
						trigger: ['change', 'blur']
					}],
					new: [{
						required: true,
						pattern: /^[A-Za-z]\w{5,15}$/,
						message: '首字符必须为字母',
						trigger: ['change', 'blur']
					}]
				},
				form: {
					old: '',
					new: ''
				},
			}
		},
		methods: {
			// 推出登录
			useLogout() {
				this.$request({
					url: '/logout',
					method: 'POST',
					success: res => {
						uni.showToast({
							title: res.data.msg,
							icon: "none"
						})
						uni.clearStorage()
					}
				})
			},
			// 修改密码
			useEditPwd() {
				this.$request({
					url: '/updatePassword',
					method: 'POST',
					data: {
						password: this.form.new,
						oldPassword: this.form.old
					},
					success: (res) => {
						if (res.data.code == "E003") {
							uni.showToast({
								title: res.data.msg,
								icon: "none"
							})
						} else {
							uni.removeStorage({
								key: 'token'
							})
							uni.showToast({
								title: res.data.msg,
							});
							setTimeout(() => {
								uni.redirectTo({
									url: '../login/login',
								})
							}, 1000)
						}
					}
				})
			},
			// 注销账号
			useDestroyAccount() {
				this.$request({
					url: '/destroyAccount',
					method: 'POST',
					success: res => {
						uni.showToast({
							title: 'res.data.msg',
							duration: 2000,
							icon: 'none'
						})
					}
				})
			}
		}
	}
</script>
<style lang="less" scoped>
	.search {
		height: 100vh;
		background-color: #f2f2f2;

		.bg {
			height: 300rpx;
			background-color: #0c34ba;
		}

		.product {
			position: relative;
			top: -50rpx;
			border-radius: 30rpx 30rpx 0 0;
			padding: 30rpx 0;
			margin: 0 20rpx;
			background-color: #fff;
			padding: 24rpx;

			.group_item {
				margin: 20rpx 0;
				padding: 14rpx 0;
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-bottom: 2rpx solid #d0d0d0;

				.item_r {
					color: gray;
				}
			}
		}
	}
</style>
